<template>
	<view class="qiun-charts3">
		<canvas :canvas-id="idName" :id="idName" class="charts3" @click="touchRing"></canvas>
	</view>
</template>

<script>
	import uCharts from '@/common/js_sdk/u-charts/u-charts.min.js';
	var _self;
	var canvaArcbar = null;
	export default {
		props:{
			/*
			{
				"name":"20%",
				"series": [{
					"data": 0.2
				}]
			}*/
			itemData:{
				type:Object,
				default:() => ({})
			},
			//必填，唯一元素id
			idName:String,
			//颜色
			color:{
				type:String,
				default:"#1FD0A3"
			}
		},
		watch:{
			idName:{
				handler(val){
					_self = this;
					this.cWidth3=uni.upx2px(150);//这里要与样式的宽高对应
					this.cHeight3=uni.upx2px(150);//这里要与样式的宽高对应
					this.arcbarWidth=uni.upx2px(15);
					this.getServerData();
				},
				immediate: true
			}
		},
		data() {
			return {
				cWidth3:'',//圆弧进度图
				cHeight3:'',//圆弧进度图
				arcbarWidth:'',//圆弧进度图，进度条宽度,此设置可使各端宽度一致
				pixelRatio:1,
			}
		},
		created() {
			_self = this;
			this.cWidth3=uni.upx2px(150);//这里要与样式的宽高对应
			this.cHeight3=uni.upx2px(150);//这里要与样式的宽高对应
			this.arcbarWidth=uni.upx2px(15);
		},
		methods: {
			touchRing(e){
				//点击事件 @touchstart="touchRing"
				this.$emit("touchRing",this.itemData)
			},
			getServerData(){
				this.itemData.series[0].color = this.color
				var chartData = {
				  "series": this.itemData.series
				}
				this.showArcbar(this.idName,chartData);
			},
			showArcbar(canvasId,chartData){
				canvaArcbar=new uCharts({
					$this:_self,
					canvasId: canvasId,
					type: 'arcbar',
					fontSize:11,
					legend:{show:false},
					background:'#FFFFFF',
					pixelRatio:_self.pixelRatio,
					series: chartData.series,
					animation: true,
					width: _self.cWidth3*_self.pixelRatio,
					height: _self.cHeight3*_self.pixelRatio,
					dataLabel: true,
					title: {
						name: '正确率',//这里我自动计算了，您可以直接给任意字符串
						color: '#999999',
						fontSize: 12*_self.pixelRatio,
						offsetY:-2*_self.pixelRatio,
					},
					subtitle: {
						name: _self.itemData.name,//这里您可以直接给任意字符串
						color: '#666666',
						fontSize: 12*_self.pixelRatio
					},
					extra: {
						arcbar:{
							type:'circle',//整圆类型进度条图
							width: _self.arcbarWidth*_self.pixelRatio,//圆弧的宽度
							startAngle:1.5//整圆类型只需配置起始角度即可
						}
					}
				});
			},
		}
	}
</script>

<style>
	/*样式的width和height一定要与定义的cWidth和cHeight相对应*/
	.qiun-charts3 {
		width: 150upx;
		height: 150upx;
		background-color: #FFFFFF;
		position: relative;
	}

	.charts3 {
		position: absolute;
		width: 150upx;
		height: 150upx;
		background-color: #FFFFFF;
	}
</style>
